/* -*- c++ -*-
   asmparser.h - LLVMIR Assembler parser
   Copyright (C) 2011 Matthew Wahab <mwb.cde@gmail.com>

   This file is part of GCC-LLVMIR.

   GCC-LLVMIR is free software; you can redistribute it and/or modify it under
   the terms of the GNU General Public License as published by the Free
   Software Foundation; either version 3, or (at your option) any later
   version.

   GCC-LLVMIR is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   for more details.

   You should have received a copy of the GNU General Public License
   along with GCC-LLVMIR; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */

#ifndef ASMPARSER_H
#define ASMPARSER_H

#include "gcc.h"
#include "parser.h"

namespace llvmir
{
  /*
   * Front-End for LLVM assembler.
   */

  /* LLVM Assembler parser */
  class AsmParser: public Parser
  {
  public:
    /*
     * Methods
     */

    /* Constructor */
    explicit AsmParser()
    { /* skip */ }

    /* Destructor */
    virtual ~AsmParser()
    { /* skip */ }

    /* Initialiser */
    void init(Context* context ATTRIBUTE_UNUSED)
    { /* skip */ }

    /* Test whether the parser accepts input from files with a given
       name.  Used to determine whether the parser should be selected
       for an input file. 

       Accepts all files.
    */
    virtual bool 
    accepts_filename(Context* context ATTRIBUTE_UNUSED, 
                     const std::string& filename ATTRIBUTE_UNUSED)
    {
      return true;
    }

    /* Toplevel parse method. Read an LLVM module from [file_name]
       which must contain valid LLVM assembler or bit-code. */
    virtual llvm::Module*
    parse_file(Context* context, const char* file_name);
  };

#ifdef LLVMIR_USE_CLANG
  /* Clang parser */
  class ClangParser: public Parser
  {
  public:
    /*
     * Fields
     */

    /* The options to pass to the clang compiler. Set-up by
       process_options. */
    StringSeq cmdline_opts;

    /*
     * Methods
     */

    /* Constructor */
    explicit ClangParser()
    { /* skip */ }

    /* Destructor */
    virtual ~ClangParser();

    /* Initialiser */
    void init(Context* context ATTRIBUTE_UNUSED)
    { /* skip */ }

    /* Test whether the parser accepts input from files with a given
       name.  Used to determine whether the parser should be selected
       for an input file. 

       Accepts files with suffix: ".c.ll", ".h.ll".
    */
    virtual bool 
    accepts_filename(Context* context ATTRIBUTE_UNUSED, 
                     const std::string& filename ATTRIBUTE_UNUSED);

    /* Process options, called after all command line arguments have
       been processed. */
    virtual bool
    process_options(Options* options);

    /* Toplevel parse method. Call Clang on filename. */
    virtual llvm::Module*
    parse_file(Context* context, const char* filename);
  };
#endif //LLVMIR_USE_CLANG

} // end of namespace llvmir

/* End of file */
#endif /* ASMPARSER_H */
